package demo3;

/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: 李白
 * @Created: 2024/4/24 17:16
 */
public class TestDemo {
    public static void main(String[] args) {
       /* Shape shape2 = new Rect();
        Shape shape1 = new Flower();
        shape2.add();
        shape1.add();*/
        Shape[] shapes = {new Rect(),new Rect(),new Flower(),new Flower()};//向上转型
        for (Shape shape:shapes) {
            shape.add();//父类调用重写的方法
        }
    }
  /*  public static void drawMap(Shape shape){
        shape.draw();
    }

    public static void main(String[] args) {
        Shape shape = new Cycle();
        Shape shape1 = new Rect();
        shape.draw();
        shape1.draw();
    }*/
}
interface Shape{//接口的方法省略了 public abstract
    public abstract void add();//接口的方法省略了 public abstract，抽象类的方法没有代码体
}
class Rect implements Shape{//类和接口建立关系，implement意思为实现
/**
 *方法的重写，多态的基础
 */
    @Override
    public void add() {//实现端口，必须重写方法，或者类是抽象类
        System.out.println("矩形");
    }
}
class Flower implements Shape{
    @Override
    public void add() {
        System.out.println("花");
    }
}

/*abstract class Shape{//抽象类
    abstract public  void draw();

}
class D extends Shape{

    @Override
    public void draw() {//每一个抽象方法都要重写

    }
}
class Cycle extends Shape{
    @Override
    public void draw() {//
        System.out.println("圆形");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("矩形");
    }
}*/
